﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace Brjostagjof_H4.Models
{
  
    public class LatestFormat
    {
        /*
         * TODO vb - format date
         */

        public Entry formatNews(Entry entry)
        {
            if (entry.title.Length > 40)
                entry.title = entry.title.Substring(0, 30) + "...";

            if (entry.content.Length > 300)
                entry.content = entry.content.Substring(0, 300) + "...";
            
            return entry;
        }

        public Entry formatEntry(Entry entry)
        {
            if (entry.entry_type == 1) // Article
            {
                if (entry.title.Length > 40)
                    entry.title = entry.title.Substring(0, 30) + "...";

                if (entry.content.Length > 350)
                    entry.content = entry.content.Substring(0, 350) + "...";   
            }

            else if (entry.entry_type == 2) // News
            {
                if (entry.title.Length > 30)
                    entry.title = entry.title.Substring(0, 30) + "...";

                if (entry.content.Length > 100)
                    entry.content = entry.content.Substring(0, 100) + "...";   
            }

            return entry;
        }

        public List<Entry> formatEntries(List<Entry> entries)
        {
            List<Entry> returnList = new List<Entry>();

            foreach (var e in entries)
                returnList.Add( formatEntry(e) );

            return returnList;
        }
    }

    public class EntryModel
    {
        [Required(ErrorMessage = "{0} má ekki vera tómur")]
        [DisplayName("Titill")]
        public string title { get; set; }

        [Required(ErrorMessage = "{0} má ekki vera tómt")]
        [DisplayName("Efni")]
        public string content { get; set; }

        [Required(ErrorMessage = "{0} verður að vera valinn")]
        [DisplayName("Flokkur")]
        public int category { get; set; }

        [Required(ErrorMessage = "{0} þarf að vera valin")]
        [DisplayName("Tegund")]
        public int entry_type { get; set; }

        public Guid userId { get; set; }

        public string posted { get; set; }

        public int id { get; set; }

        [DisplayName("Staða")]
        public int entry_status { get; set; }
    }

    /// <summary>
    /// Defining the entryType object, an article (Grein = 1) or news item (Frétt = 2).
    /// </summary>
    public class entryType
    {
        //BrjostagjofDBDataContext db = new BrjostagjofDBDataContext();
       
        public int typeID { get; set; }
        
        public string name { get; set; }
       
        public static IEnumerable<entryType> entryTypes = new List<entryType> 
        { 
            new entryType {
               typeID = 1,
               name = "Grein"
            },
            new entryType {
                typeID = 2,
                name = "Frétt"
            }
        };
    }

    /// <summary>
    /// Model to list all entries
    /// </summary>
    public class EntryListModel
    {
        public string title { get; set; }
        public string author { get; set; }
        public string posted { get; set; }
        public string type { get; set; }
        public int ID { get; set; }
    }
}